package groep3.ssc.model;

import java.util.ArrayList;

public class Scheme
{

    private ArrayList<SchemeEntry> entries = new ArrayList<SchemeEntry>();
    private String title;
    private String abbreviation;
    private int id = 0;

    public Scheme(String title, String abbreviation)
    {
        this.title = title;
        this.abbreviation = abbreviation;
    }

    public void addEntry(SchemeEntry entry)
    {
        if (entries.size() > 0)
        {
            entry.setTotalTime(entry.getLapTime() + entries.get(entries.size() - 1).getTotalTime());
        } else
        {
            entry.setTotalTime(entry.getLapTime());
        }
        this.entries.add(entry);
    }

    public String getTitle()
    {
        return title;
    }

    public void setTitle(String title)
    {
        this.title = title;
    }

    public String getAbbreviation()
    {
        return abbreviation;
    }

    public void setAbbreviation(String abbreviation)
    {
        this.abbreviation = abbreviation;
    }

    public ArrayList<SchemeEntry> getEntries()
    {
        return entries;
    }

    public int getId()
    {
        return this.id;
    }

    public void setId(int insertId)
    {
        this.id = insertId;

    }

    public String toString()
    {
        return this.getTitle();
    }

    public void setEntries(ArrayList<SchemeEntry> schemeEntries)
    {
        this.entries = schemeEntries;
    }

    public SchemeEntry getEntry(long entryId)
    {
        return null;
    }

    public void removeEntry(SchemeEntry entry)
    {
        for (int i = 0; i < getEntries().size(); i++)
        {
            if (this.entries.get(i).getId() == entry.getId())
            {
                this.entries.remove(i);
            }
        }
        //TODO: Lapnumbers updaten
    }

    public SchemeEntry getLap(int currentLap)
    {
        if (currentLap < 1)
        {
            return new SchemeEntry(0, 0);
        } else if (entries.size() >= currentLap)
        {
            return entries.get(currentLap - 1);
        } else

        {
            return null;
        }
    }
}
